<?php
/**
 * @author kwor
 * @url http://www.kwor.cn
 *
 */
header("Content-Type:text/html;charset=".SN_CHARSET);
require_once 'data/mysql_config.php';
require_once 'inc/lib/base/lib_mob_wap.php';
require_once 'inc/lib/base/lib_common.php';
session_ini();
require_once 'inc/lib/base/cls_template.php';
require_once 'inc/lib/admin/lib_admin.php';
$xueniao = new cls_template;
$tempath='default';
$lang='zh_cn';
$xueniao->cache_dir      = "../temp/cache/";
include_once("lang/".$lang."/base.php");
$siteinfo_c=array(
systeminfo=>$lang['systeminfo'],
charset=>'<meta http-equiv="Content-Type" content="text/html; charset='.SN_CHARSET.'" />',
checkcode=>'inc/lib/base/lib_chkcode.php',
version=>SYS_VERSION,
);


//$m=browseinfo();//目前算法不安全
$m='iknow';


if($m!=='Unknown browse'){ //非正常浏览器一律展示手机页面
	$xueniao->template_dir ="templates/".$tempath."/";
	$xueniao->compile_dir    = "../temp/compiled/admin";
	$siteinfo_c['tempdir']="templates/".$tempath."/";

}else {

	$xueniao->template_dir ="mob_templates/default/";
	$siteinfo_c['tempdir']="mob_templates/default/";
	$xueniao->compile_dir    = "../temp/compiled/admin/mob";
	
}



$xueniao->assign("siteinfo",$siteinfo_c);

$login_lang_c=array(
username=>$lang['username'],
password=>$lang['password'],
chkcode=>$lang['chkcode'],
changechkcode=>$lang['changechkcode'],
clickback=>$lang['clickback'],
);

$xueniao->assign('loginlang',$login_lang_c);
switch ($_REQUEST['action']) {
	case 'login':
	
		if($m!=='Unknown browse'){ //浏览器正常时需要验证码。
			if(chkcode($_REQUEST['sn'])!==true){
				sys_msg($lang['chkcodewrong'], 1);
			}
		}
		$name=trim($_REQUEST['user']);
		$pwd=trim(md5($_REQUEST['pwd']));
		$res=$db->getrow("select * from sn_admin where name='".$name."'");
		if($res)
		{
			if($res['isdel']=='N'){
				if($res['password']<> $pwd){
					$login_msg=$lang['psswrong'];
				}else {
					//验证管理员类型
					if($res['admintype']==1 || $res['admintype']==2 ||$res['admintype']==3 )
					{
						$los=admin_session($name,$pwd,$res['admintype'],$res['id']);

					}else{
						$xueniao->display('login.htm');
					}

				}
			}else {
				$login_msg=$lang['usernameisdel'];
			}
		}else {
			$login_msg=$lang['usernamewrong'];
		}

		if($los==true)
		{
			local_header('main.php');
		}else {
			$xueniao->assign('loginmsg',$login_msg);
			$xueniao->display('login.htm');
		}
		break;
	case 'logout':
		if(unset_admin_session()==false){

			$login_msg=$lang['loginoutwrong'];
		}
		$xueniao->assign('loginmsg',$login_msg);
		$xueniao->display('login.htm');
		break;
	default:
		$xueniao->display('login.htm');

		break;
}
?>